home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE23
/
CLINIC
/
MOMU.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-04-28
|
4KB
|
137 lines
unit MOMU;
interface
uses
WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TMOMForm = class(TForm)
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MOMForm: TMOMForm;
implementation
{$R *.DFM}
procedure ActivateWindow(Caption, ClassName: PChar);
var
FormWnd, AppWnd: HWnd;
begin
FormWnd := FindWindow(ClassName, Caption);
if FormWnd = 0 then
raise Exception.Create('Cannot find window');
{$ifdef Win32}
{ Having found the form, now find the Application window }
{ Can't reliably use GetParent, so... }
AppWnd := GetWindowLong(FormWnd, gwl_HWndParent);
{ Tell the Delphi Application window to pop up in case it }
{ is minimised. Bear in mind that FindWindow only works on }
{ top-level windows, not child windows. Delphi forms are }
{ top-level popup windows which have parents, so the following }
{ check should only try and restore a parent window if it }
{ is a Delphi app }
if (AppWnd <> HWnd_Desktop) and IsIconic(AppWnd) then
SendMessage(AppWnd, wm_SysCommand, sc_Restore, 0);
{ Tell the form window to pop up if it is minimised }
if IsIconic(FormWnd) then
SendMessage(FormWnd, wm_SysCommand, sc_Restore, 0);
{ Make the target form be in front and active }
SetForegroundWindow(FormWnd);
{$else}
AppWnd := GetWindowWord(FormWnd, gww_HWndParent);
if (AppWnd <> HWnd_Desktop) and IsIconic(AppWnd) then
SendMessage(AppWnd, wm_SysCommand, sc_Restore, 0);
if IsIconic(FormWnd) then
SendMessage(FormWnd, wm_SysCommand, sc_Restore, 0);
BringWindowToTop(FormWnd);
{$endif}
end;
procedure RunApp(AppName: String);
{$ifdef Win32}
var
SI: TStartupInfo;
PI: TProcessInformation;
begin
GetStartupInfo(SI);
if not CreateProcess(nil, PChar(AppName), nil,
nil, False, 0, nil, nil, SI, PI) then
{$else}
var
Buf: array[0..255] of Char;
begin
if WinExec(StrPCopy(Buf, AppName), sw_ShowNormal) < HInstance_Error then
{$endif}
raise Exception.Create('Failed to run ' + AppName)
end;
procedure RunOrSwitchToApp(const AppPath: String; ClassName: PChar);
begin
try
ActivateWindow(nil, ClassName)
except
RunApp(AppPath)
end
end;
procedure TMOMForm.FormCreate(Sender: TObject);
begin
{$ifdef Win32}
BorderStyle := bsToolWindow;
ClientHeight := 25;
{$endif}
end;
procedure TMOMForm.SpeedButton1Click(Sender: TObject);
begin
RunOrSwitchToApp('c:\excel\excel.exe', 'XLMAIN')
end;
procedure TMOMForm.SpeedButton2Click(Sender: TObject);
begin
RunOrSwitchToApp('c:\word6\winword.exe', 'OpusApp')
end;
procedure TMOMForm.SpeedButton6Click(Sender: TObject);
begin
RunOrSwitchToApp('c:\delphi\delphi.exe', 'TAppBuilder')
end;
procedure TMOMForm.SpeedButton3Click(Sender: TObject);
begin
RunOrSwitchToApp('calc.exe', 'SciCalc')
end;
procedure TMOMForm.SpeedButton4Click(Sender: TObject);
begin
RunOrSwitchToApp('notepad.exe', 'Notepad')
end;
procedure TMOMForm.SpeedButton5Click(Sender: TObject);
begin
Close
end;
end.